package reflect;

import java.lang.reflect.Field;

public class ReflectDemo8 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchFieldException {
        Class cls = Class.forName("reflect.Teacher");
        Object obj = cls.newInstance();
        Field field = cls.getDeclaredField("name");
        field.setAccessible(true);
        field.set(obj, "刘恒");
        System.out.println(field.get(obj));
        field.setAccessible(false);
    }
}
